package com.example.photography.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.photography.R;
import com.example.photography.bean.Interest_Bean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class InterestGridViewAdapter extends MyBaseAdapter {
    private Boolean sign = false;

    public InterestGridViewAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_interset, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根据位置得到对应的数据
        Interest_Bean.DataBean.InterestBean interestBean = (Interest_Bean.DataBean.InterestBean) list.get(position);
        viewHolder.svInterest.setImageURI(Uri.parse(interestBean.getImage()));
        viewHolder.tvName.setText(interestBean.getText());
        ViewHolder finalViewHolder = viewHolder;
        viewHolder.rlInterest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (sign) {
                    sign = false;
                    finalViewHolder.ischoose.setImageResource(R.drawable.point_false);
                } else {
                    sign = true;
                    finalViewHolder.ischoose.setImageResource(R.drawable.point_true);
                }
            }
        });
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.sv_interest)
        SimpleDraweeView svInterest;
        @BindView(R.id.ischoose)
        ImageView ischoose;
        @BindView(R.id.rl_interest)
        RelativeLayout rlInterest;
        @BindView(R.id.tv_name)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
